package com.library.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.library.bean.Book;
import com.library.bean.Page;
import com.library.service.BookService;
import com.library.service.impl.BookServiceImpl;

@WebServlet("/getBook.do")
public class GetBookServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int pageNum;
		int pageSize;
		try {
			pageNum=Integer.parseInt(req.getParameter("pageNum"));
		} catch (Exception e) {
			pageNum=1;
		}
		
		try {
			pageSize=Integer.parseInt(req.getParameter("pageSize"));
		} catch (Exception e) {
			pageSize=10;
		}
		BookService bs=new BookServiceImpl();
		Page<Book> book =bs.selectAll(pageNum, pageSize);
		req.setAttribute("bookPage", book);
		req.getRequestDispatcher("book.jsp").forward(req, resp);
	}
}
